<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()	+ path + "/";%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>">
		<title><s:text name="sys.app_title" /></title>
		<%@include file="../include/contentheader.jsp"%>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
		<script type="text/javascript" src="js/app.js"></script>
		<link rel="stylesheet" type="text/css" href="css/main.css" />
		<link rel="stylesheet" type="text/css" href="css/dtree.css" />
		<script type="text/javascript" src="js/dtree.js"></script>
		<script type="text/javascript" src="dwr/engine.js"></script>
		<script type="text/javascript" src="dwr/util.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/dwr/interface/departmentDwrJs.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/dwr/interface/categoryManager.js"></script>
		<script type="text/javascript" src="js/dep.js"></script>
		<link rel="stylesheet" href="css/dep.css" type="text/css" />
		<script type="text/javascript">
			function doSelect(dsid,dsname,parameterType){				
				window.close();
				if(parameterType=="depTree"){
					location.href="excelToolAssetCardCheckDep.action?dsname="+dsname;
				}else if(parameterType=="sortTree"){
					location.href="excelToolAssetCardCheckSort.action?dsid="+dsid;
				}
			}
			function doOk(){
				if(window.returnValue == undefined){
					window.returnValue = '';
				}
				window.close();
			}
			function doCancel(){
				window.returnValue = '';
				window.close();
			}
			//显示部门树
			function showDepTree(){
				var deptree=document.getElementById("deptree");
				var sorttree=document.getElementById("sorttree");	
				sorttree.style.display="none";	
				deptree.style.display="block";
			}
			//显示类别树
			function showSortTree(){
				var deptree=document.getElementById("deptree");
				var sorttree=document.getElementById("sorttree");	
				deptree.style.display="none";	
				sorttree.style.display="block";
			}
		</script>
	</head>
	<body>
		<div class="mainContainer">
  	 	<div class="headerTitle">选择导出资产的条件</div>
  	 	<div><input type="button" onclick="doOk();" value="确定" /><input type="button" onclick="doCancel();" value="取消" /></div>
      	 	<div id="deptree">
       			<div>
       				<input type="button" value="显示类别树" onclick="showSortTree();" style="width: 80px;"/>
       			</div>
       			<div id="myTree1" style="width:100%;height:383px;overflow-y:auto;color:#333333;border:1px solid #C0C0C0;border-right:0px;border-bottom:0px;">
       			<script type="text/javascript">
       			var myTree1=document.getElementById("myTree1");
   				d1 = new dTree('d1');
   				var inner1;
   				var parameterType1;
   				buildTree1();
   				function buildTree1(){
   					departmentDwrJs.getAllDepartment(function(departmentList) {
   					d1.add(0, -1, '广元电业局');
   					parameterType1="depTree";
    				for(var i=0; i<departmentList.length; i++){
        				for(var j=0; j<departmentList.length; j++){
            				if(departmentList[i].depid==departmentList[j].depparentid){
        						d1.add(departmentList[j].depid,departmentList[j].depparentid,departmentList[j].depname,"javascript:doSelect(\'"+departmentList[j].depid+"\',\'"+departmentList[j].depname+"\',\'"+parameterType1+"\')");
        					}
            			}
    				}
    				inner1 = d1.toString();
    				showBuildTree1();
    				});
    			}
				function showBuildTree1(){
					myTree1.innerHTML = inner1;
	  	 		}
				</script>
				</div>
			</div>
			<div id="sorttree" style="display: none;">
        		<div>
        			<input type="button" value="显示部门树" onclick="showDepTree();" style="width: 80px;"/>
       	 		</div>
        		<div id="myTree" style="width:100%;height:383px;overflow-y:auto;color:#333333;border:1px solid #C0C0C0;border-right:0px;border-bottom:0px;">
				<script type="text/javascript">
					var myTree = document.getElementById("myTree");
					d = new dTree('d');
					var inner;
					var parameterType;
					buildTree();
					function buildTree(){
						categoryManager.findAllCategory(function(category) {
							d.add(0, -1, '广元电业局');
							parameterType="sortTree";
							for(var i=0; i<category.length; i++){
								var size = category[i].catid.length;
								var url = "javascript:doSelect(\'"+category[i].catid+"\',\'"+category[i].catname+"\',\'"+parameterType+"\')";
								if(size == 3){
									d.add(category[i].catid,0,category[i].catname,url);
								}else if(size == 6){
									d.add(category[i].catid,category[i].catid.substr(0,3),category[i].catname,url);
								}else if(size == 10){
									d.add(category[i].catid,category[i].catid.substr(0,6),category[i].catname,url);
								}
							}
							inner = d.toString();
							showBuildTree();
						});
					}
					function showBuildTree() {
						myTree.innerHTML = inner;
					}
				</script>
				</div>
			</div>
		</div>
	</body>
</html>